<template>
	<!-- 刘亚鹏 2023-4-4 小程序购物车 -->
	<view style="width: 96%;margin-left: 2%;">
		<!-- 页头 -->
		<!-- <u-navbar
			height="44px"
			title="购物车"
			:autoBack="true"
		></u-navbar> -->
		<!-- 分段器 -->
		<view class="u-demo-block" style="margin-top: 10px;">
			<view class="u-demo-block__content">
				<u-subsection
					:list="list"
					mode="subsection"
					:current="current1"
					@change="change1"
					activeColor="#da85af"
				></u-subsection>
			</view>
		</view>
		<!-- 购物车为空显示 -->
		<view class="empty" v-if="isEmpty">
			<!-- <image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309" mode="widthFix" style="width: 400rpx;"></image>
		<view class="empty-text">空空如也的购物</view>
		<view class="empty-button" @click="goshopping">去选购</view> -->
		<u-empty
			mode="car"
			icon="http://cdn.uviewui.com/uview/empty/car.png">
		</u-empty>
		<view class="empty-button" @click="goshopping" style="margin-top: 20rpx;">去选购</view>
		</view>
		<!-- 购物车不为空展示 -->
		<view v-if="show==true" style="margin-top: 20px;width: 100%;">
			<view style="width: 100%;box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1);border-radius: 10px;margin-bottom: 20px;float: left;" v-for="(item,index) in commInfoArray" :key="index">
				<uni-swipe-action-item :right-options="options" @click="onClick($event, item)" @change="change" :auto-close="false">
					<view>
						<view style="width: 100%;height: 20px;">					<view style="font-weight: bold;color: gray;padding: 10px;">{{item.businessName}} ></view>				</view>
<!-- :style="{height: item.height}" -->				<view style="width: 100%;background-color: #fff;">					<view style="float: left;width: 40%;margin: 6% 0 0 5%;">							<checkbox-group @change="selected(item)" style="width: 25%;float: left;margin-top: 20%;">								<label>									<checkbox color="#555555" :checked='(item.flag =="true"?true:false)'/>								</label>							</checkbox-group>							<image :src="'http://101.43.223.224:8765/image/getImageById?id='+ (item.imgId==null?'':item.imgId.split(',')[0])" style="width: 150rpx;height: 160rpx;border-radius: 10px;" @click="toGoodsView(item)"></image>					</view>					<view style="width: 54%;float: left;padding: 20px 0 20px 0;" class="size">					    <view style="font-size: 30rpx;margin-bottom: 4%;" @click="toGoodsView(item)">{{item.commName}}</view>
						<view class="" style="width: 100%;" @click="toGoodsView(item)">
							<span style="font-size: 10px;">{{item.back}}</span>
						</view>					    <view style="margin-top: 6%">							<view style="width: 50%;float: left;" class="goods-price"><span style="font-size: 10px;">￥</span></i><span style="margin-left: 1px;margin-right: 1px;font-weight: bold;">{{item.price}}</span>/件</view>							
							<view style="float: right;margin-right: 2%;width: 40%;margin-top: 2%;" class="detail-right">								<view class="subtract" @click="reduce(item)" style="width: 40rpx;height: 40rpx;border-radius: 80rpx 10rpx 10rpx 80rpx;background-color: gainsboro;float: left;text-align: center;">-</view>								<view style="float: left;background: gainsboro;width: 40rpx;height: 40rpx;text-align: center;margin: 0 3%;">{{item.number}}</view>								<view @click="add(item)" class="add" style="width: 40rpx;height: 40rpx;border-radius: 10rpx 80rpx 80rpx 10rpx;text-align: center;
								background: gainsboro;float: left;">+</view>
							</view>
							<view style="width: 70%;float: left;" class="goods-price"><span style="color: red;font-size: 20rpx;">预估到手价：￥{{item.favPrice}}/件</span></view>						</view>					</view>				</view>
					</view>
				</uni-swipe-action-item>
			</view>
		</view>
		<!-- diy展示 -->
		<view style="margin-top: 20px;width: 100%;">
			<view style="width: 100%;box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.1);border-radius: 10px;margin-bottom: 20px;float: left;" v-for="(item,index) in diyInfoArray" :key="index">
				<uni-swipe-action-item :right-options="options"@click="onClick($event, item)" @change="change" :auto-close="false">
					<view>
						<view style="width: 100%;height: 20px;">
					<view style="font-weight: bold;color: gray;padding: 10px;float: left;">{{item.businessName}}DIY></view>
					<view style="height: 40rpx;width: 10%;float: right;background: #ff50ab;text-align: center;border-radius: 5px;color: #fff;margin: 20rpx 30rpx 0 0;">DIY</view>
				</view>
				<view style="width: 100%;background-color: #fff;clear: both;">
					<view style="float: left;width: 40%;margin: 6% 0 0 5%;">

							<checkbox-group @change="selected(item)" style="width: 25%;float: left;margin-top: 20%;">
								<label>
									<checkbox color="#555555" :checked='(item.flag =="true"?true:false)'/>
								</label>
							</checkbox-group>
							<image :src="'http://101.43.223.224:8765/image/getImageById?id='+ (item.diyImageId==null?'':item.diyImageId.split(',')[0])" style="width: 150rpx;height: 160rpx;border-radius: 10px;"></image>
					</view>
					<view style="width: 54%;float: left;padding: 20px 0 20px 0;" class="size">
						<view style="font-size: 30rpx;margin-bottom: 4%;">{{item.diyName}}</view>
						<!-- <view class="" style="width: 100%;">
							<span style="font-size: 10px;">{{item.back}}</span>
						</view> -->
						<view style="margin-top: 6%">
							<view style="width: 50%;float: left;" class="goods-price"><span style="font-size: 10px;">￥</span></i><span style="margin-left: 1px;margin-right: 1px;font-weight: bold;">{{item.diyPrice}}</span>/件</view>
							<view style="float: right;margin-right: 2%;width: 40%;margin-top: 2%;" class="detail-right">
								<view class="subtract" @click="reduce(item)" style="width: 40rpx;height: 40rpx;border-radius: 80rpx 10rpx 10rpx 80rpx;background-color: gainsboro;float: left;text-align: center;">-</view>
								<view style="float: left;background: gainsboro;width: 40rpx;height: 40rpx;text-align: center;margin: 0 3%;">{{item.number}}</view>
								<view @click="add(item)" class="add" style="width: 40rpx;height: 40rpx;border-radius: 10rpx 80rpx 80rpx 10rpx;text-align: center;
								background: gainsboro;float: left;">+</view>
							</view>
							<view style="width: 70%;float: left;" class="goods-price"><span style="color: red;font-size: 20rpx;">预估到手价：￥{{item.diyFavorablePrice}}/件</span></view>
						</view>
					</view>
				</view>
					</view>
				</uni-swipe-action-item>
			</view>
		</view>
		<view style="width: 100%;height: 100rpx;float: left;margin-bottom: 200rpx;"></view>
		<view class="end">
			<view class="end-left">
				<checkbox-group @change="selectgoods()">
					<label>
						<checkbox  :checked="allchecked" />全选
					</label>
				</checkbox-group>
				<view>
					总计：<text style="color: #f00;font-weight: bold;">￥ {{totalPricess}}</text>
				</view>
			</view>
			<view class="end-right" @click="closeAnAccount">
				结算({{totalNum}})
			</view>
		</view>
	</view>
</template>

<script>
import ShoppingTrolleyVue from './ShoppingTrolley.vue'
	export default{
		data(){
			return{
				// 购物车为空或者不为空是否展示变量
				show:true,
				// 底部全选变量
				allchecked:true,
				// 勾选商品
				// checked:true,
				// 商品信息数组
				commInfoArray:[],
				// diy信息数组
				diyInfoArray:[],
				// 右滑商品展示的内容
				options:[
					{
						text: '移入收藏',
						style: {
							backgroundColor: '#ffb027'
						}
					}, {
						text: '删除',
						style: {
							backgroundColor: '#dd524d'
						}
					}
				],
				// 分段器
				current1: 0,
				// 分段器类型
				list: ['全部', '一天内', '十天内', '一月内'],
				// 控制是否显示购物车为空页面
				isEmpty: false,
				// 选中商品数量
				totalNum11:0,
				// 用户id
				userInfo: {}
			}
		},
		onLoad(){
			// 查询用户信息
			this.getUserInfo()
			// 查询用户的购物车信息
			this.selectShoppingCart()
		},
		// 监听页面刷新
		onShow() {
		    // 查询用户的购物车信息
		    this.selectShoppingCart()
		},
		methods:{
			// 获取用户信息
			getUserInfo(){
				this.userInfo = wx.getStorageSync('user')
			},
			// 默认查询用户的购物车全部信息
			selectShoppingCart(){
				this.$myRequest({
					url:'/AppletShoppingCart/selectShoppingCart',
					data:{typeId:0,type:"查询全部",userId:this.userInfo.id}
				}).then(res =>{
					if(res.data.flag){
						this.commInfoArray = res.data.data
						// // 全选框状态判定
						// this.fullCheckboxStatusDetermination()
						// if(this.commInfoArray.length+this.){
						// 	this.isEmpty = true
						// 	this.allchecked = false
						// }else{
						// 	this.isEmpty = false
						// }
						// 查询用户diy信息
						this.selectDiyInfo()
					}else{
						uni.showToast({
							title: '查询失败，请稍后再试！'
						})
					}
				})
			},
			// 查询diy记录
			selectDiyInfo(){
				this.$myRequest({
					url:'/AppletShoppingCart/selectShoppingCart',
					data:{typeId:2,type:"查询Diy记录",userId:this.userInfo.id}
				}).then(res =>{
					if(res.data.flag){
						this.diyInfoArray = res.data.data
						// 全选框状态判定
						this.fullCheckboxStatusDetermination()
						if(this.commInfoArray.length+this.diyInfoArray.length === 0){
							this.isEmpty = true
							this.allchecked = false
						}else{
							this.isEmpty = false
						}
					}else{
						uni.showToast({
							title: '查询失败，请稍后再试！'
						})
					}
				})
			},
			// 底部全选框状态判定
			fullCheckboxStatusDetermination(){
				let num = 0;
				let num1 = 0;
				const that = this
				const a = that.commInfoArray.forEach((item)=>{
					// 计算选中的商品有多少
					item.flag=="true" ? num += item.number : num += 0
				})
				const b = that.diyInfoArray.forEach((item)=>{
					// 计算选中的diy有多少
					item.flag=="true" ? num1 += item.number : num1 += 0
					
				})
				// 如果选中的商品和购物车内所有商品数量一致就是全选了
				const sumnum = num + num1
				if(that.totalNum1 === sumnum){
					if(sumnum !== 0){
						that.allchecked=true
					}else{
						that.allchecked = false
					}
				}else{
					that.allchecked=false
				}
			},
			// 如果购物车无商品就跳转购物页面
			goshopping(){
				uni.navigateTo({
					//保留当前页面，跳转到应用内的某个页面
					url: '/pages/index/PopularRecommendation',
				})
			},
			// change时间
			change(e){
				console.log(e)
			},
			// 选中商品
			selected(item){
				const that = this
				// 如果是选中商品
				if(item.flag === "false"){
					item.flag = "true"
					this.$myRequest({
						method:'POST',
						url:'/AppletShoppingCart/persistingFlag',
						data:{userId:that.userInfo.id,typeId:3,id:item.id}
					}).then(res =>{
						if(res.data.flag){
							console.log('单选成功')
						}else{
							console.log('单选失败')
						}
					})
					let num = 0;
					let num1 = 0;
					const a = that.commInfoArray.forEach((item)=>{
						// 计算选中的商品有多少
						item.flag=="true" ? num += item.number : num += 0
					})
					const b = that.diyInfoArray.forEach((item)=>{
						// 计算选中的商品有多少
						item.flag=="true" ? num1 += item.number : num1 += 0
					})
					let sumnum = num+num1
					// 如果选中的商品和购物车内所有商品数量一致就是全选了
					if(that.totalNum1 === sumnum){
						that.allchecked=true
						this.$myRequest({
							method:'POST',
							url:'/AppletShoppingCart/persistingFlag',
							data:{typeId:1,userId:this.userInfo.id}
						}).then(res =>{
							if(res.data.flag){
								this.selectShoppingCart()
							}else{
								console.log('勾选全部商品失败')
							}
						})
					}else{
						that.allchecked=false
					}
					// 如果是取消勾选
				}else if(item.flag === "true"){
					// 全选框为false
					that.allchecked = false
					item.flag = "false"
					this.$myRequest({
						method:'POST',
						url:'/AppletShoppingCart/persistingFlag',
						data:{userId:this.userInfo.id,typeId:4,id:item.id}
					}).then(res =>{
						if(res.data.flag){
							console.log('取消成功')
						}else{
							console.log('取消失败')
						}
					})
				}else{
					console.log('出现错误，商品状态不详')
				}
				// item.flag=!item.flag
				// if(!item.flag){
				// 	this.allchecked=false
				// 	// that.$myRequest({
				// 	// 	method:'POST',
				// 	// 	url:'/AppletShoppingCart/persistingFlag',
				// 	// }).then(res =>{
				// 	// 	if(res.data.flag){
				// 	// 	}else{
				// 	// 	}
				// 	// })
				// }else{
				// 	let num = 0;
				// 	const a=this.commInfoArray.forEach((item)=>{
				// 		// 计算选中的商品有多少
				// 		item.flag=="true" ? num += item.number : num += 0
				// 		// 如果选中的商品和购物车内所有商品数量一致就是全选了
				// 		console.log('totalNum1' + this.totalNum1)
				// 		console.log('num' + num)
				// 		if(this.totalNum1 === num){
				// 			this.allchecked=true
				// 			console.log('执行2')
				// 		}else{
				// 			this.allchecked=false
				// 			console.log('执行3')
				// 		}
				// 		// return item.flag===true
				// 	})
				// 	// if(a){
				// 	// 	this.allchecked=true
				// 	// }else{
				// 	// 	this.allchecked=false
				// 	// }
				// }
			},
			// 全选商品
			selectgoods(){
				// 底部全选框为true或者false
				this.allchecked=!this.allchecked
				// // 如果全选中
				if(this.allchecked){
					this.allchecked=true
					// this.commInfoArray.map(item=>{
					// 	item.flag=true
					// })
					// 全部勾选商品
					this.$myRequest({
						method:'POST',
						url:'/AppletShoppingCart/persistingFlag',
						data:{typeId:1,userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							this.selectShoppingCart()
							this.selectDiyInfo()
						}else{
							console.log('勾选全部商品失败')
						}
					})
				}
				else{
					this.allchecked=false
					// this.commInfoArray.map(item=>{
					// 	item.flag=false
					// })
					// 全部取消勾选商品
					this.$myRequest({
						method:'POST',
						url:'/AppletShoppingCart/persistingFlag',
						data:{typeId:2,userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							this.selectShoppingCart()
						}else{
							console.log('取消全选失败')
						}
					})
				}
			},
			// 全选框
			// selectgoods(){
			// 	 // 通过商品的选择框控制全选的框子     
			// 	get(){
			// 		 // 当选中商品的数量等于商品的总数量是，表示商品被全选了
			// 		if(this.totalNum === this.commInfoArray.length){
			// 			// 全选框选中
			// 			return true;     
			// 		}else{
			// 			// 全选框未选中
			// 			return false;
			// 		}
			// 	},
			// 	// 操作全选框，改变所有商品的选中情况
			// 	set(e){
			// 		if(e){
			// 			this.commInfoArray.forEach(item => {
			// 				// 让购物车的每一项都选中
			// 				return item.flag = true;
			// 			})
			// 		}else{
			// 			// 全选框没有被选中      
			// 			this.commInfoArray.forEach(item => {
			// 				// 购物车的每一项都未选中
			// 				return item.flag = false;
			// 			})
			// 		}
			// 	}
			// },
			// 减少商品数量方法
			reduce(item){
				let number=item.number
				if(number>1){
					// number=1
					item.number = number-1
					this.$myRequest({
						method:'POST',
						url:'/AppletShoppingCart/persistingUserShoppingCartInfo',
						data:{id:item.id,userId:this.userInfo.id,number:item.number}
					}).then(res=>{
						if(res.data.flag){
							// 重新查询购物车信息
							this.selectShoppingCart()
						}else{
							console.log('error')
						}
					})
				}else if(number=1){
					uni.showToast({
					title:"该宝贝不能减少了哟~" 
				})
				}
				// item.number=number
			},
			// 添加商品数量方法
			add(item){
				let number =item.number
				item.number=number+1
				this.$myRequest({
					method:'POST',
					url:'/AppletShoppingCart/persistingUserShoppingCartInfo',
					data:{id:item.id,userId:this.userInfo.id,number:item.number}
				}).then(res=>{
					if(res.data.flag){
						// 重新查询购物车信息
						this.selectShoppingCart()
					}else{
						console.log('error')
					}
				})
			},
			// 右滑框点击事件
			onClick(e,item){
			  console.log('点击了'+(e.position === 'left' ? '左侧' : '右侧') + e.content.text + '按钮')
			  // 删除购物车商品
			  const that = this
			  if(e.content.text === '删除'){
				  uni.showModal({
					  title: '提示',
					  // 提示文字
					  content: '确认从购物车删除此商品吗？',
					  // 取消按钮的文字自定义
					  cancelText: "取消",
					  // 确认按钮的文字自定义
					  confirmText: "删除",
					  //删除字体的颜色
					  confirmColor:'red',
					  //取消字体的颜色
					  cancelColor:'#000000',
					  success: function(res) {
					  if (res.confirm) {
						  // 执行确认后的操作
						  that.$myRequest({
							  method:'POST',
							  url:'/AppletShoppingCart/delItemsInShoppingCart',
							  data:{id:item.id,userId:that.userInfo.id}
						  }).then(res =>{
							  if(res.data.flag){
								  // 如果是在全部页面进行删除的话就查询全部
								  if(that.current1 === 0){
									  that.selectShoppingCart()
									  that.selectDiyInfo()
								  // 如果是在一天内页面进行删除的话就查询一天内
								  }else if(that.current1 === 1){
									  that.$myRequest({
									  	url:'/AppletShoppingCart/selectShoppingCart',
									  	// userId 为死数据后续登录完善后再改动
									  	data:{typeId:1,type:'查询一天或者十天内的记录',userId:that.userInfo.id}
									  }).then(res =>{
									  	if(res.data.flag){
									  		that.commInfoArray = res.data.data
											that.$myRequest({
												url:'/AppletShoppingCart/selectShoppingCart',
												data:{typeId:1,type:'查询一天或十天内的Diy记录',userId:that.userInfo.id}
											}).then(res =>{
												if(res.data.flag){
													that.diyInfoArray = res.data.data
													if(that.commInfoArray.length+that.diyInfoArray.length === 0){
														that.isEmpty = true
														that.allchecked = false
													}else{
														that.isEmpty = false
													}
												}else{
													console.log('查询失败')
												}
											})
									  	}else{
									  		uni.showToast({
									  			title: '查询失败，请稍后再试！'
									  		})	
									  	}
									  })
								  }else if(that.current1 === 2){
									  that.$myRequest({
									  	url:'/AppletShoppingCart/selectShoppingCart',
									  	// userId 为死数据后续登录完善后再改动
									  	data:{typeId:10,type:'查询一天或者十天内的记录',userId:that.userInfo.id}
									  }).then(res =>{
									  	if(res.data.flag){
									  		that.commInfoArray = res.data.data
									  		that.$myRequest({
									  			url:'/AppletShoppingCart/selectShoppingCart',
									  			data:{typeId:10,type:'查询一天或十天内的Diy记录',userId:that.userInfo.id}
									  		}).then(res =>{
									  			if(res.data.flag){
									  				that.diyInfoArray = res.data.data
									  				if(that.commInfoArray.length+that.diyInfoArray.length === 0){
									  					that.isEmpty = true
									  					that.allchecked = false
									  				}else{
									  					that.isEmpty = false
									  				}
									  			}else{
									  				console.log('查询失败')
									  			}
									  		})
									  	}else{
									  		uni.showToast({
									  			title: '查询失败，请稍后再试！'
									  		})	
									  	}
									  })
								  } else if(that.current1 === 3){
									  that.$myRequest({
									  	url:'/AppletShoppingCart/selectShoppingCart',
									  	// userId 为死数据后续登录完善后再改动
									  	data:{typeId:1,type:'查询一月内的记录',userId:that.userInfo.id}
									  }).then(res =>{
									  	if(res.data.flag){
									  		that.commInfoArray = res.data.data
									  		that.$myRequest({
									  			url:'/AppletShoppingCart/selectShoppingCart',
									  			data:{typeId:1,type:'查询一月内Diy的记录',userId:that.userInfo.id}
									  		}).then(res =>{
									  			if(res.data.flag){
									  				that.diyInfoArray = res.data.data
									  				if(that.commInfoArray.length+that.diyInfoArray.length === 0){
									  					that.isEmpty = true
									  					that.allchecked = false
									  				}else{
									  					that.isEmpty = false
									  				}
									  			}else{
									  				console.log('查询失败')
									  			}
									  		})
									  	}else{
									  		uni.showToast({
									  			title: '查询失败，请稍后再试！'
									  		})	
									  	}
									  })
								  }else{
									  console.log('参数有误')
								  }
								  uni.showToast({
									  title: '删除成功',
									  icon: 'none',
									  duration: 2000
								  })
							  }else{
								  uni.showToast({
									  title: '删除失败',
									  icon: 'none',
									  duration: 2000
								  })
							  }
						  })
					  } 
					  else {
						  // 执行取消后的操作
					  }
				  }
			  })
			  }else if(e.content.text === '移入收藏'){
				  this.$myRequest({
					  method:'POST',
					  url:'/AppletShoppingCart/cartMoveIntoCollection',
					  data:{id:item.id,userId:this.userInfo.id,diyId:item.diyId,isNoDiy:item.isNoDiy}
				  }).then(res =>{
					  if(res.data.flag){
						  that.selectShoppingCart()
						  that.selectDiyInfo()
						  uni.showToast({
							title: '移入成功',
							icon: 'none',
							duration: 2000
						  })
					  }else{
						  uni.showToast({
							title: '移入失败',
							icon: 'none',
							duration: 2000
						  })
					  }
				  })
			  }else{
				  console.log('未知操作')
			  }
			},
			// 右滑框事件
			swipeChange(e,index){
			  console.log('当前状态：'+ e +'，下标：' + index)
			},
			// 分段器切换事件
			change1(index) {
				// 如果查询全部记录
				if(index === 0){
					this.$myRequest({
						url:'/AppletShoppingCart/selectShoppingCart',
						// userId 为死数据后续登录完善后再改动
						data:{typeId:0,type:'查询全部',userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							// 查询diy记录
							this.$myRequest({
								url:'/AppletShoppingCart/selectShoppingCart',
								data:{typeId:2,type:'查询Diy记录',userId:this.userInfo.id}
							}).then(res =>{
								this.diyInfoArray = res.data.data
								this.fullCheckboxStatusDetermination()
							})
							this.commInfoArray = res.data.data
							// 计算商品数量
							let num = this.diyInfoArray.length
							let num1 = this.commInfoArray.length
							if(num + num1 === 0){
								this.isEmpty = true
								this.allchecked = false
							}else{
								this.isEmpty = false
							}
						}else{
							uni.showToast({
								title: '查询失败，请稍后再试！'
							})	
						}
					})
				// 如果查询一天内或者十天的记录
				}else if(index === 1){
					this.$myRequest({
						url:'/AppletShoppingCart/selectShoppingCart',
						// userId 为死数据后续登录完善后再改动
						data:{typeId:1,type:'查询一天或者十天内的记录',userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							// 查询diy记录
							this.$myRequest({
								url:'/AppletShoppingCart/selectShoppingCart',
								data:{typeId:1,type:'查询一天或十天内的Diy记录',userId:this.userInfo.id}
							}).then(res =>{
								this.diyInfoArray = res.data.data
								this.fullCheckboxStatusDetermination()
							})
							this.commInfoArray = res.data.data
							// 计算商品数量
							let num = this.diyInfoArray.length
							let num1 = this.commInfoArray.length
							if(num + num1 === 0){
								this.isEmpty = true
								this.allchecked = false
							}else{
								this.isEmpty = false
							}
						}else{
							uni.showToast({
								title: '查询失败，请稍后再试！'
							})	
						}
					})
				}else if(index === 2){
					this.$myRequest({
						url:'/AppletShoppingCart/selectShoppingCart',
						// userId 为死数据后续登录完善后再改动
						data:{typeId:10,type:'查询一天或者十天内的记录',userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							// 查询diy记录
							this.$myRequest({
								url:'/AppletShoppingCart/selectShoppingCart',
								data:{typeId:10,type:'查询一天或十天内的Diy记录',userId:this.userInfo.id}
							}).then(res =>{
								this.diyInfoArray = res.data.data
								this.fullCheckboxStatusDetermination()
							})
							this.commInfoArray = res.data.data
							// 计算商品数量
							let num = this.diyInfoArray.length
							let num1 = this.commInfoArray.length
							if(num + num1 === 0){
								this.isEmpty = true
								this.allchecked = false
							}else{
								this.isEmpty = false
							}
						}else{
							uni.showToast({
								title: '查询失败，请稍后再试！'
							})	
						}
					})
				// 如果查询一个月内的数据
				}else if(index === 3){
					this.$myRequest({
						url:'/AppletShoppingCart/selectShoppingCart',
						// userId 为死数据后续登录完善后再改动
						data:{typeId:1,type:'查询一月内的记录',userId:this.userInfo.id}
					}).then(res =>{
						if(res.data.flag){
							// 查询diy记录
							this.$myRequest({
								url:'/AppletShoppingCart/selectShoppingCart',
								data:{typeId:1,type:'查询一月内Diy的记录',userId:this.userInfo.id}
							}).then(res =>{
								this.diyInfoArray = res.data.data
								this.fullCheckboxStatusDetermination()
							})
							this.commInfoArray = res.data.data
							// 计算商品数量
							let num = this.diyInfoArray.length
							let num1 = this.commInfoArray.length
							if(num + num1 === 0){
								this.isEmpty = true
								this.allchecked = false
							}else{
								this.isEmpty = false
							}
						}else{
							uni.showToast({
								title: '查询失败，请稍后再试！'
							})	
						}
					})
				}
			  this.current1 = index
			},
			// 结算按钮
			closeAnAccount(){
				uni.navigateTo({
					//保留当前页面，跳转到应用内的某个页面
					url: '/pages/shoppingtrolley/CloseAnAccount',
				})
			},
			// 跳转到商品详情页
			toGoodsView(item){
				uni.navigateTo({
					//保留当前页面，跳转到应用内的某个页面
					url: '/pages/goods/GoodsView?id=' + item.commodityId,
				})
			}
		},
		// 计算
		computed:{
			// 商品总数量
			totalNum(){
				let totalNum2 = 0
				let totalNum1 = 0
				this.commInfoArray.map(item => {
				    item.flag=="true" ? totalNum2 += item.number : totalNum2 += 0
				})
				this.diyInfoArray.map(item => {
				    item.flag=="true" ? totalNum1 += item.number : totalNum1 += 0
				})
				let totalNum = totalNum1 + totalNum2
				return totalNum
				// let arr=this.commInfoArray.filter(r=>{
				// 	return r.flag === 'true';     // 查找选择框被选中的商品,并将它们返回给数组arr
				// });
				// console.log('arr.length' +arr.length);
				// return arr.length; 
			},
			totalNum1(){
				let totalNum3 = 0;
				let totalNum2 = 0;
				this.commInfoArray.map(item => {
				    totalNum3 = totalNum3+item.number
				})
				this.diyInfoArray.map(item => {
				    totalNum2 = totalNum2+item.number
				})
				let totalNum1 = totalNum3+totalNum2
				return totalNum1
			},
			// 商品总价钱
			totalPricess() {
				// 商品总价钱
			    let totalPrices = 0;
				// diy总价钱
				let totalPrices1 = 0;
				// 遍历算商品价格
			    this.commInfoArray.map(item => {
			        item.flag=="true" ? totalPrices += item.number * item.favPrice : totalPrices += 0
			    })
				// 遍历算diy价格
				this.diyInfoArray.map(item => {
				    item.flag=="true" ? totalPrices1 += item.number * item.diyFavorablePrice : totalPrices1 += 0
				})
				const totalPricess = totalPrices + totalPrices1
			    return totalPricess;
			},
		}
	}
	
</script>

<style scoped lang="scss">
.goods{
	line-height: 80rpx;
	background-color: #FFFFFF;
	&-detail{
		display: flex;
		padding: 30rpx 15rpx 30rpx 30rpx;
		background-color: #fff;
		justify-content: space-between;
		border-bottom: 5rpx solid #F1F1F1;
		align-items: center;
		.detail-left{
			display: flex;
			.goods-left{
				display: flex;
				align-items: center;
		}
	}
	.size{
		display: flex;
		justify-content: space-around;
		flex-direction: column;
		margin-left: 30rpx;
		.goods-price{
			font-size: 25rpx;
			color: #F44545;
			
		}
	}
	.detail-right{
		text{
			width: 50rpx;
			line-height: 50rpx;
			text-align: center;
			display: inline-block;
			background-color: #F7F7F7;
			margin-right: 10rpx;
		}
		.add {
			color: red;
			border-radius: 10rpx 30rpx 30rpx 10rpx;
			margin-right: 20rpx;
		}
		.subtract{
			width: 200px;
			border-radius: 30rpx 10rpx 10rpx 30rpx;
		}
	}
	}
}
.empty{
	position: relative;
	top: 220rpx;
	text-align: center;
	display: flex;
	align-items: center;
	flex-direction: column;
	&-text{
		color: #808080;
		margin-bottom: 50rpx;
	}
	&-button{
		width: 300rpx;
		height: 90rpx;
		color:orange;
		border: 1rpx solid orange;
		text-align: center;
		line-height: 90rpx;
		border-radius: 48rpx;
	}		
}
.end{
	width: 100%;
	height: 90rpx;
	background-color:#fff;
	position: fixed;
	bottom: 0rpx;
	left: 0;
	display: flex;
	align-items: center;
	&-left{
		width: 70%;
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		.end-flex{
			display: flex;
			align-items: center;
		}
	}
	&-right{
		width: 30%;
		line-height: 90rpx;
		background-color: #F44545;
		text-align: center;
		color: #fff;
	}
}
.content-box {
	flex: 1;
	height: 44px;
	line-height: 44px;
	padding: 0 15px;
	position: relative;
	background-color: #fff;
	border: 1px solid #f5f5f5;
}
.album {
	@include flex;
	align-items: flex-start;

	&__avatar {
		background-color: $u-bg-color;
		padding: 5px;
		border-radius: 3px;
	}

	&__content {
		margin-left: 10px;
		flex: 1;
	}
}
</style>
